package com.bua.control;

import com.bua.adapter.IImageSetter;
import com.bua.net.Tool;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Bitmap.Config;
import android.graphics.Matrix;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class ZZTButton extends LinearLayout implements IImageSetter {

	private ImageView ivGuan = null;
	private ImageView ivMao = null;
	private ImageView ivGen = null;

	private Boolean isZZT = false;
	public ZZTButton(Context context )
	{
		super(context);		
		ivGuan = new ImageView(context);
		ivMao =  new ImageView(context);
		ivGen =  new ImageView(context);
		
		if (this.getTag() != null) {
			ivGuan.setImageBitmap(BitmapFactory.decodeStream(Tool.getFile(
					context, "zzt", "guan" + this.getTag() , "jpg")));

			ivMao.setImageBitmap(BitmapFactory.decodeStream(Tool.getFile(
					context, "zzt", "mao" + this.getTag() , "jpg")));

			ivGen.setImageBitmap(BitmapFactory.decodeStream(Tool.getFile(
					context, "zzt", "gen" + this.getTag() , "jpg")));
		}
		
		
			this.addView(ivGuan, 2);
			this.addView(ivMao, 1);
			this.addView(ivGen, 0);
		
	}
	public ZZTButton(Context context,int tag , boolean isShang) {
		super(context);
		this.setTag(tag);
		this.setOrientation(VERTICAL);
		ivGuan = new ImageView(context);
		ivMao =  new ImageView(context);
		ivGen =  new ImageView(context);
		
		if (this.getTag() != null) {

			ivGen.setImageBitmap(BitmapFactory.decodeStream(Tool.getFile(
					context, "zzt", "gen" + this.getTag() , "png")));
		}
		
		if(isShang)
		{
			this.addView(ivGen, 0);
			this.addView(ivMao, 1);
			this.addView(ivGuan, 2);
		}
		else
		{
			this.addView(ivGuan, 0);
			this.addView(ivMao, 1);
			this.addView(ivGen, 2);
		}
	}

	void setGen(Bitmap bm) {
		isZZT=true;
		ivGen.setImageBitmap(bm);
	}

	void setYa(Bitmap bm) {
		isZZT=false;
		ivGen.setImageBitmap(bm);
		ivGuan.setImageBitmap(null);
		ivMao.setImageBitmap(null);

	}

	void setGuan(Bitmap bm) {

		if (isZZT) {
			ivGuan.setImageBitmap(bm);
		}
	}

	void setMao(Bitmap bm) {

		if (isZZT) {
			ivMao.setImageBitmap(bm);
		}
	}

	@Override
	public void setImageSeg(int seg, String name) {
		// TODO Auto-generated method stub
		Bitmap bm = BitmapFactory.decodeStream(Tool.getFile(
				this.getContext(), "zzt", name,"png"));
		switch (seg) {
		case 0:
		{
			Bitmap temp = BitmapFactory.decodeStream(Tool.getFile(this.getContext(), "zzt",
					name, "png"));
			Bitmap dstBitmap = temp.copy(Config.ARGB_8888, true);
			dstBitmap.eraseColor(Color.WHITE);
			setYa(dstBitmap);
		}
		break;
		case 1: {
			setGen(bm);
		}
			break;
		case 2: {
			setYa(bm);
		}
			break;
		case 3: {
			setMao(bm);
		}

			break;
		case 4: {
			setGuan(bm);
		}

			break;

		default:
			break;
		}
	}
}
